import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/network/file_preview_http.dart';
import 'package:kq_flutter_core_widget/utils/file_preview_util.dart';
import 'package:kq_flutter_core_widget/utils/log.dart';
import 'package:kq_flutter_core_widget/utils/native/file_picker_native_util.dart';
import 'package:kq_flutter_core_widget/widgets/image/kq_image.dart';
import 'package:kq_flutter_core_widget/widgets/imageBox/kq_image_box.dart';
import 'package:kq_flutter_widgets/widgets/button/kq_outline_button.dart';
import 'package:kq_flutter_widgets/widgets/titleBar/kq_title_bar.dart';
import 'package:kq_flutter_widgets_example/router/route_map.dart';

/// 文件选择demo
class FilePickerPage extends StatefulWidget {
  const FilePickerPage({Key? key}) : super(key: key);

  @override
  FilePickerPageState createState() => FilePickerPageState();
}

class FilePickerPageState extends State<FilePickerPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: '文件选择与文件预览',
        back: () {
          Get.back();
        },
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Wrap(
          spacing: 10.r,
          runSpacing: 10.r,
          children: [
            KqOutlineButton(
              title: '拍照',
              onTap: () async {
                var file = await FilePickerNativeUtil.takePhoto();
                if (file != null) {
                  Log.d(file, tag: 'filePicker');
                }
              },
            ),
            KqOutlineButton(
              title: '选择图片',
              onTap: () async {
                var files = await FilePickerNativeUtil.pickImages(maxCount: 2);
                Log.d(files, tag: 'filePicker');
              },
            ),
            KqOutlineButton(
              title: '选择文件',
              onTap: () async {
                var files = await FilePickerNativeUtil.pickFiles(maxCount: 2);
                Log.d(files, tag: 'filePicker');
              },
            ),
            KqOutlineButton(
              title: '预览文件（txt）',
              onTap: () async {
                FilePreviewUtil.previewFile(
                    url: 'http://115.236.167.250:8888/Test/打分规则.txt',
                    fileName: '打分规则.txt');
              },
            ),
            KqOutlineButton(
              title: '预览文件（docx）',
              onTap: () async {
                FilePreviewUtil.previewFile(
                    url: 'http://115.236.167.250:8888/Test/test.docx',
                    fileName: 'test.docx');
              },
            ),
            KqOutlineButton(
              title: '预览文件（png）',
              onTap: () async {
                FilePreviewUtil.previewFile(
                    url:
                        'https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF',
                    fileName: 'xzg_logo.png');
              },
            ),
            KqOutlineButton(
              title: '预览多个图片',
              onTap: () async {
                FilePreviewUtil.previewImg([
                  ImageUrl(
                      imageType: ImageType.http,
                      url:
                          'https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF'),
                  ImageUrl(
                      imageType: ImageType.http,
                      url:
                          'https://img2.baidu.com/it/u=2937346062,2864430088&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333'),
                  ImageUrl(
                      imageType: ImageType.http,
                      url:
                          'https://img0.baidu.com/it/u=3109574663,3521128999&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500'),
                ], position: 1);
              },
            ),
            KqOutlineButton(
              title: '预览文件（xlsx）',
              onTap: () async {
                FilePreviewUtil.previewFile(
                    url:
                        'http://115.236.167.250:8888/Test/移动端小诸葛PDA转Flutter进度汇总.xlsx',
                    fileName: '移动端小诸葛PDA转Flutter进度汇总.xlsx');
              },
            ),
            KqOutlineButton(
              title: '预览文件（csv）',
              onTap: () async {
                FilePreviewUtil.previewFile(
                    url:
                        'http://115.236.167.250:8888/Test/小诸葛移动端迭代1.48任务汇总_20230406.csv',
                    fileName: '小诸葛移动端迭代1.48任务汇总_20230406.csv');
              },
            ),
            KqOutlineButton(
              title: '预览文件（pptx）',
              onTap: () async {
                FilePreviewUtil.previewFile(
                    url: 'http://115.236.167.250:8888/Test/小诸葛注塑标准云系统功能介绍.pptx',
                    fileName: '小诸葛注塑标准云系统功能介绍.pptx');
              },
            ),
            KqOutlineButton(
              title: '预览文件（pdf）',
              onTap: () async {
                FilePreviewUtil.previewFile(
                    url: 'http://115.236.167.250:8888/Test/云产品缺陷等级及处理措施.pdf',
                    fileName: '云产品缺陷等级及处理措施.pdf');
              },
            )
          ],
        ),
      ),
    );
  }
}
